package com.situ.stl.job;

import com.situ.stl.entity.Reserve;
import com.situ.stl.service.ReserveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class ReserveStatusJob {
    @Autowired
    private ReserveService reserveService;
    @Scheduled(cron = "0/50 * * * * *")
    public void CleanJob() throws Exception {
        //查询所有的预约信息
        List<Reserve> reserveList = reserveService.select(null);
        for (Reserve reserve : reserveList) {
            //获取当前时间
          long nowTime =  new Date().getTime();
            //上课中
            if (reserve.getCourse().getTime().getTime()<nowTime && (reserve.getCourse().getTime().getTime() + reserve.getCourse().getLength() * 60 *1000) > nowTime){
                reserve.setStatus(2);
                reserveService.modifyReserve1(reserve);
            }
            //已完课
            if ((reserve.getCourse().getTime().getTime() + reserve.getCourse().getLength() * 60 *1000) < nowTime){
                reserve.setStatus(3);
                reserveService.modifyReserve1(reserve);
            }

        }


    }
}
